{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution(object):\n",
    "    def convertToTitle(self, n):\n",
    "        \"\"\"\n",
    "        :type n: int\n",
    "        :rtype: str\n",
    "        \"\"\"\n",
    "        # Make a set of num-char pairs\n",
    "        conv = {}\n",
    "        cnt = 0\n",
    "        for w in range(ord('A'), ord('Z') + 1):\n",
    "            conv[cnt] = chr(w)\n",
    "            cnt = cnt + 1            \n",
    "\n",
    "        title = ''\n",
    "        while n > 0:\n",
    "            n = n - 1\n",
    "            title = conv[n%26] + title\n",
    "            n = n // 26\n",
    "\n",
    "        return title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Solution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'J'"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.convertToTitle(10)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
